package com.zhang.jedis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author zhangchenghui
 * @version 1.0.0
 * @ClassName MyJedisPoll.java
 * @createTime 2021年09月04日 18:04:00
 * @Description
 */
public class MyJedisPool {
    private static JedisPool jedisPool;

    public static Jedis getResource() {
        if (jedisPool == null ) {
            JedisPoolConfig poolConfig = new JedisPoolConfig();
            poolConfig.setMinIdle(3); //最小闲置连接数
            poolConfig.setMaxIdle(5); //最大闲置连接数
            poolConfig.setMaxTotal(10); //最大可用连接数

            poolConfig.setBlockWhenExhausted(true); //连接耗尽是否等待
            poolConfig.setMaxWaitMillis(2000); //等待时间
            poolConfig.setTestOnBorrow(true); //取连接的时候进行一下测试 ping pong


            jedisPool = new JedisPool(poolConfig,"192.168.75.102",6379);
        }
        return  jedisPool.getResource();
    }

}
